<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<!-- 下拉框 -->
 <link rel="stylesheet" href="/static/ace/css/chosen.css" /> 
<!-- 日期框 -->
 <link rel="stylesheet" href="/static/ace/css/datepicker.css" /> 
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<link rel="stylesheet" href="/layui/css/layui.css">
<script src="/layui/layui.js"></script>
 <script src="/static/ace/js/bootbox.js"></script>
<!-- ace scripts -->
<script src="/static/ace/js/ace/ace.js"></script>
<!-- 下拉框 -->
<script src="/static/ace/js/chosen.jquery.js"></script>
<!-- 日期框 -->
<script src="/static/ace/js/date-time/bootstrap-datepicker.js"></script>
<!--提示框-->
<script type="text/javascript" src="/static/js/jquery.tips.js"></script> 
<style type="text/css">
</style>
</head>
<body class="layui-layout-body">
	<div class="layui-form"  style="margin-top: 20px;">
		<div class="layui-form toolbar">
			<div class="layui-form-item">
				<div class="layui-inline">
					<div class="layui-inline">
						<div class="layui-input-inline mr0" style="margin-left: 10px;">
						<input type="text" class="layui-input" id="test6" autocomplete="off" placeholder="选择日期范围">
					  	</div>
					  	</div>
	              	 <div class="layui-inline">
					  </div>
					<div class="layui-inline">
						<div class="layui-input-inline mr0">
							<input id="authEdtSearch" class="layui-input" type="text" autocomplete="off" placeholder="输入账号关键字">
						</div>
					</div>
					<div class="layui-inline">
						<button id="authBtnSearch" class="layui-btn icon-btn layui-btn-normal">搜索</button>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!--  数据data -->
	<div class="layui-row" style="padding: 10px 10px;" id="tablediv">
		<table id="table_data" lay-filter="test"  ></table>	
	</div>
	<!-- 表格操作列 -->
	<script type="text/html" id="authTableBar">
  		<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="details">详情</a>
  		<a class="layui-btn layui-btn-xs" style="background-color: #5FB878;" lay-event="ratify">批准</a>
  		<a class="layui-btn layui-btn-danger layui-btn-xs"  lay-event="del" id="del">驳回</a>
	</script>


	
	<script type="text/javascript">
	$(top.hangge());//关闭加载状态
	
	layui.use('laydate', function(){
		  var laydate = layui.laydate;
		  
		//日期范围
		  laydate.render({
		    elem: '#test6'
		    ,range: true
		  });
	});
	var layer ;
	var active;
	layui.use('layer', function(){
	    layer = layui.layer;
	}); 
	var tableIns ;
	var layer ;
	layui.use(['layer', 'form', 'table','element'], function(){
		  var table = layui.table;
		  var form = layui.form;
		  var element = layui.element;
		  layer=layui.layer;
		  
		  //加载层
		  var loadingIndex =layer.msg('数据加载中...', {
			   icon: 16
			  ,shade: 0.01
		  });  
		  
		  //第一个实例
		  var params = {};
		  tableIns = table.render({
		    elem: '#table_data',
		    url: '/admin/account/selectCondition4',
		    page: true, //开启分页
		    where:params,
		    loading:true,
		    height: 'full-150',
		    cols: [
		    	[ //表头
		    	{field:'id',title: '编号', hide: true}
               , {field: 'name', title: '姓名'}
               , {field: 'phone', title: '电话',width:120}
               , {field: 'email', title: '邮箱'}
               , {field: 'img', title: '头像路径'}
               , {field: 'sex', title: '性别',width:62,templet:function(s){
            	   if(s.sex==0){
            		   return "保密";
            	   } else if(s.sex==1){
            		   return "男";
            	   } else if (s.sex==2){
            		   return "女";
            	   }
               }}
               , {field: 'age', title: '年龄',width:62}
               , {field: 'educationBackground', title: '学历',width:90}
               , {field: 'school', title: '毕业院校'}
               , {field: 'brithday', title: '用户生日',width:164}
               , {field: 'createtime', title: '注册时间',width:164}
               , {field: 'isstate', title: '账号状态',width:90,templet:function(i){
            	   if(i.isreport==1){
            		   return "被举报";
            	   } else if(i.isstate==1){
            		   return "申述中";
            	   } else if(i.isbanned==1){
            		   return "被封禁";
            	   } else if(i.isactivate==0){
            		   return "待审核";
            	   } else {
            		   return "正常"
            	   }
               }}
		       , {templet: '#authTableBar', minWidth: 210, align: 'center', title: '操作'}
		    	]
		   		],
		    done:function(res){
		    	layer.close(loadingIndex);
		    }
		  });
		  
		  //数据操作
		  table.on('tool(test)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			    var data = obj.data //获得当前行数据
			    ,layEvent = obj.event; //获得 lay-event 对应的值
			    var id=data.id;
			    if(layEvent === 'del'){
			    	unAuditData(id);
			    } else if(layEvent === 'ratify'){
			    	layer.confirm('确认同意审批！', function(index){
				        layer.close(index);
				        //向服务端发送删除指令
			    		showEditModel(id);//批准
			    	});
			    } else if(layEvent === 'details'){
			    	details(id);//详情
			    }
			  });
	});
	
	function unAuditData(id) {
		let dataMessage = '<div class="layui-form-item layui-form-text"><div class=""><textarea placeholder="请输入驳回理由" class="layui-textarea" id="unratifyMessage"></textarea></div></div>'
		layer.open({
	        title: '请输入驳回理由'
	        ,type:1
	        , area: ["300px",]
	        , btn: ['确定']
	        , content: dataMessage
	        , yes: function (index) {
	        	let params = {};
	        	params.id = id;
	        	let message = $("#unratifyMessage").text()+'';
	        	if($.trim(message) === ''){
	        		message = "你提交数据异常，管理员驳回了你的申请！";
	        	}
	        	params.message = message;
	        	$.ajax( {
	       	        url : '/admin/account/list4_del', 
	       	        type : 'post',
	       	        data: params,
	       	        dataType : 'json',
	       	        success : function(data) {
	       	        	if(data.code==0){
	                		 layer.msg(data.msg,{icon: 1});
	    	        	 }else{
	    	        		 layer.msg(data.msg,{icon: 2});
	    	        	 }
	       	        	Refresh();
	       	        }
	       	    });
	        	layer.close(index);
	        }
		});
	};
	
	function showEditModel(id){
		let params = {};
    	params.id = id;
    	$.ajax( {
   	        url : '/admin/account/ratify', 
   	        type : 'post',
   	        data: params,
   	        dataType : 'json',
   	        success : function(data) {
   	        	if(data.code==0){
            		 layer.msg(data.msg,{icon: 1});
	        	 }else{
	        		 layer.msg(data.msg,{icon: 2});
	        	 }
   	        	Refresh();
   	        }
   	    });
	}
	
	function details(id) {
		layer.open({
			title:'学生账号详情',
			content: '/admin/account/list4_details?id='+id,
			type: 2,
			area: ['80%','80%'],
			cancel: function(index, layero){ 
				  
			  },
			  end:function(){
				  Refresh();
			  }
		});
	}
	
	//搜索
	$("#authBtnSearch").click(function(){
		Refresh();
	});
	//刷新
	function Refresh(){
		var params = {};
		var authEdtSearch=$("#authEdtSearch").val();
		var status=$("#status").val();
		var time6=$("#test6").val();
		params.keywords=authEdtSearch;
		params.status=status;
		params.time6=time6;
		tableIns.reload({
			  where:params
			  ,page: {
				    curr: 1 //重新从第 1 页开始
				  }
		});	
	}
	
	</script>


</body>
</html>